package com.guigu.serviceorder.service.impl;

import com.guigu.serviceorder.entity.CategoryReport;
import com.guigu.serviceorder.mapper.CategoryReportMapper;
import com.guigu.serviceorder.service.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
public class CategoryReportServiceImpl implements CategoryReportService
{

    @Autowired
    private CategoryReportMapper categoryReportMapper;


    @Override
    public List<CategoryReport> categoryReport(LocalDate date) {
        return categoryReportMapper.categoryReport(date);
    }

    @Override
    @Transactional
    public void createData() {
        //查询昨天的类目统计数据
        LocalDate localDate=LocalDate.now().minusDays(1);
        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(localDate);

        //保存到tb_category_report
        for (CategoryReport categoryReport:categoryReports){
            categoryReportMapper.insert(categoryReport);
        }
    }

    @Override
    public List<Map> category1Count(String date1, String date2) {
        return categoryReportMapper.category1Count(date1,date2);
    }

    @Override
    public List<Map> namenum(String date1, String date2) {
        return categoryReportMapper.namenum(date1,date2);
    }

    @Override
    public List<Map> ordersourcenum(String date1) {
        return categoryReportMapper.ordersourcenum(date1);
    }
}
